﻿<UserControl x:Class="TV_Organizer.Subtitles.SubtitlesControl"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:tvofs="clr-namespace:TV_Organizer.FileScanner"
             xmlns:tvo="clr-namespace:TV_Organizer"
             xmlns:tvos="clr-namespace:TV_Organizer.Subtitles"
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300">
  <UserControl.Resources>
    <tvo:SeasonConverter x:Key="SeasonConverter" />
    
    <Style TargetType="CheckBox">
      <Setter Property="Width" Value="16" />
    </Style>
  </UserControl.Resources>
  
  <Grid>
    <Grid.ColumnDefinitions>
      <ColumnDefinition Width="*" />
      <ColumnDefinition Width="5" />
      <ColumnDefinition Width="2*" />
    </Grid.ColumnDefinitions>

    <Grid.RowDefinitions>
      <RowDefinition Height="Auto" />
      <RowDefinition Height="Auto" />
      <RowDefinition Height="*" />
    </Grid.RowDefinitions>
    
    <GridSplitter Grid.Row="1" Grid.Column="1" Grid.RowSpan="10" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
                  Background="Black" Cursor="SizeWE" ResizeDirection="Columns" />

    <!--  BUTTONS  -->
    <StackPanel Orientation="Horizontal">
      <Button Name="SearchSubtitlesButton" Margin="0,0,5,5" Grid.Column="0" Click="SearchSubtitlesButton_Click">Search subs</Button>
      <Button Name="DownloadSelectedSubtitlesButton" Margin="0,0,5,5" Grid.Column="1" Click="DownloadSelectedSubtitlesButton_Click">Download selected subtitles</Button>

      <TextBlock Margin="0,0,5,5" VerticalAlignment="Center" Text="Language:" />
      <ComboBox Name="LanguageComboBox" Margin="0,0,5,5" MinWidth="50" />
    </StackPanel>

    <!--  FilesListView  -->
    <ListView x:Name="FilesListView" Grid.Row="2" Grid.Column="0">
      <ListView.View>
        <GridView>
          <GridViewColumn DisplayMemberBinding="{Binding Path=Filename}" Header="File" />
          <GridViewColumn DisplayMemberBinding="{Binding Path=Extension}" Header="Type" />

          <GridViewColumn DisplayMemberBinding="{Binding Path=Season, Converter={StaticResource SeasonConverter}}">
            <GridViewColumn.Header>
              <TextBlock Text="S" />
            </GridViewColumn.Header>
          </GridViewColumn>
          <GridViewColumn DisplayMemberBinding="{Binding Path=Episode, Converter={StaticResource SeasonConverter}}">
            <GridViewColumn.Header>
              <TextBlock Text="E" />
            </GridViewColumn.Header>
          </GridViewColumn>

          <GridViewColumn>
            <GridViewColumn.Header>
              <TextBlock Text="# Subs" ToolTip="Number of selected subtitles out of the total number of subtitles." />
            </GridViewColumn.Header>
            <GridViewColumn.CellTemplate>
              <DataTemplate>
                <TextBlock>
                  <Run Text="{Binding Path=SelectedSubtitles.Count, Mode=OneWay}" />
                  <Run Text="/" />
                  <Run Text="{Binding Path=Subtitles.Count, Mode=OneWay}" />
                </TextBlock>
              </DataTemplate>
            </GridViewColumn.CellTemplate>
          </GridViewColumn>
        </GridView>
      </ListView.View>
    </ListView>
    
    <!-- SUBTITLES LIST -->
    <ListView x:Name="SubtitlesListView" Grid.Row="2" Grid.Column="2" Margin="5,0,0,0" ItemsSource="{Binding SelectedItem.Subtitles, Source={x:Reference FilesListView}}"
              PreviewMouseDoubleClick="SubtitlesListView_PreviewMouseDoubleClick">
      <ListView.View>
        <GridView>
          <GridViewColumn Header="Download">
            <GridViewColumn.CellTemplate>
              <DataTemplate>
                <CheckBox IsChecked="{Binding Subtitle.IsSelected}" />
              </DataTemplate>
            </GridViewColumn.CellTemplate>
          </GridViewColumn>
          <GridViewColumn DisplayMemberBinding="{Binding Path=SimilarityPercentage}" Header="%" />
          <GridViewColumn DisplayMemberBinding="{Binding Path=Subtitle.Filename}" Header="Filename" />
          <GridViewColumn DisplayMemberBinding="{Binding Path=Subtitle.Language}" Header="Language" />
          <GridViewColumn DisplayMemberBinding="{Binding Path=Subtitle.Source}" Header="Source" />
        </GridView>
      </ListView.View>
    </ListView>
  </Grid>
</UserControl>
